package top.maof.book.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import top.maof.book.model.Book;
import top.maof.book.model.Shelf;

import java.util.List;

@Mapper
public interface ShelfMapper extends BaseMapper<Shelf> {
    int deleteByPrimaryKey(Integer id);

//    int insert(Shelf record);

    int insertSelective(Shelf record);

    Shelf selectByPrimaryKey(Integer id);

    @Delete("delete from shelf where user_id = #{userId} and book_id = #{bookId}")
    int deleteByForeignKey(@Param("userId") int userId, @Param("bookId") int bookId);

    int updateByPrimaryKeySelective(Shelf record);

    int updateByPrimaryKey(Shelf record);

    // 获取用户书架(收藏)
    @Select("select * from v_user_shelf_book where user_id = #{usrId}")
    List<Book> getProfileShelf(Integer usrId);

    //判断用户是否收藏了本书
    @Select("select * from shelf where user_id = #{userId} and book_id = #{bookId}")
    Shelf select(int userId, int bookId);

    // 获取书的收藏量
    @Select("select count(user_id) from shelf where book_id = #{bookId}")
    Integer shelfNum(int bookId);
}
